package service;

import java.util.ArrayList;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.eclipse.jdt.internal.compiler.ast.ArrayAllocationExpression;

import util.MybatisUtil;

import dao.WorkingDao;
import dao.WorkingMapper;
import entity.Working;

public class WorkingService {

	WorkingDao dao = new WorkingDao();
	
	public void testselect(){
		SqlSession sqlSession = null;
		List<Working> wList = new ArrayList<Working>();
		try {
			sqlSession = MybatisUtil.createSqlSession();
			
			wList = sqlSession.getMapper(WorkingMapper.class).getList();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			MybatisUtil.closeSqlSession(sqlSession);
		}
	}
	
	public void testsava(){
		SqlSession sqlSession = null;
		int count = 0;
		try {
			sqlSession = MybatisUtil.createSqlSession();
			
			Working w = new Working();
			
			count = sqlSession.getMapper(WorkingMapper.class).save(w);
			
			sqlSession.commit();
		} catch (Exception e) {
			e.printStackTrace();
			sqlSession.rollback();
		}finally{
			MybatisUtil.closeSqlSession(sqlSession);
		}
	}
	
	public void testid(int id){
		SqlSession sqlSession = null;
		int count = 0;
		try {
			sqlSession = MybatisUtil.createSqlSession();
			//count = 
			sqlSession.getMapper(WorkingMapper.class).getWorking(id);
			
			sqlSession.commit();
		} catch (Exception e) {
			e.printStackTrace();
			sqlSession.rollback();
		}finally{
			MybatisUtil.closeSqlSession(sqlSession);
		}
	}
	
}
